package com.wwz.leetcode;

/**
 * @Description: 找到第二大的 比较是不是大两倍就好了
 * @create: 2022-01-13 16:23:31
 * @author:wwz
 */
public class LeetCode747 {
    public static int dominantIndex(int[] nums) {
        if (nums.length <= 1) {
            return 0;
        }
        int index = 0;
        int max = nums[0];
        // 第二大的数字
        int max2 = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > max) {
                max2 = max;
                max = nums[i];
                index = i;
            } else if (max2 < nums[i]) {
                max2 = nums[i];
            }
        }
        return max >= max2 * 2 ? index : -1;
    }

    public static void main(String[] args) {
//        int[] aa = {0, 2, 0, 3};
//        int[] aa = {1,0,0};
        int[] aa = {0, 0, 2, 1};
//        int[] aa = {0, 0, 3, 2};
        System.out.println(dominantIndex(aa));
    }
}
